import React, { useReducer } from 'react';

function handleNum(state, action) {
  switch (action.type) {
    case 'add':
      return state + 1
    case 'delete':
      return state - 1
    default:
      return 0
  }
}

function UseReducer() {
  const [num, dispatch] = useReducer(handleNum, 0)
  return (
    <div className='hook-state'>
      <p>{num} </p>
      <button onClick={() => dispatch({type:'add'})}>addNumber</button>
      <button onClick={() => dispatch({type:'delete'})}>deleteNumber</button>
      <button onClick={() => dispatch({type:null})}>changeNumber</button>
    </div>
  )
}

export default UseReducer